structure Main: MAIN =
struct

structure Ast = Ast()
type 'a t = Ast.Program.t
structure E = ErrorMsg
  
structure Parse = Parse (structure Ast = Ast)

exception Failed

val strParsing = "// after parsing\n\n"
  
fun main filename =
    let val _ = (E.reset()
               ; E.fileName := filename)
        fun say s = 
            if true 
            then print s 
            else ()
        val _ = say (String.concat ["compile: ", filename, " starting\n"])
        val _ = say "lexing and parsing starting\n"  
        val ast = Parse.parse filename
        val _ = if (!E.anyErrors) then raise E.Error else ()
        val _ = say "lexing and parsing finished\n\n"
        val _ = say (String.concat ["compile: ",  filename, " finished\n"])
    in ()
    end

fun mainWrap (name, args) =
let val _ = case args
				of [] => print ("Usage: jc <file>\n")
				| x::xs => main x
	in
		OS.Process.success
end

val _ = SMLofNJ.exportFn ("jc-compile", mainWrap)

end
